package com.ymatou.iapi.godmch.testcase;

import java.text.SimpleDateFormat;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.List;
import java.util.Locale;

import org.json.JSONArray;
import org.json.JSONObject;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.godmch.parameter.addPointBean;
import com.ymatou.iapi.godmch.parameter.getMyPointDetailBean;
import com.ymatou.iapi.godmch.service.getMyPointDetailCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
import com.ymttest.database.model.godmch.point_change_detail;
import com.ymttest.database.model.godmch.point_change_detailExample;
import com.ymttest.database.sqlwapper.godmch.point_change_detailWapper;
/**
*获取我的积分
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_getMyPointDetail{
	private static getMyPointDetailBean bean;
	private static getMyPointDetailCall call;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("获取我的积分");
	}

	@Before
	public void caseUp() {
		bean=new getMyPointDetailBean();
		call=new getMyPointDetailCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(call.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getMyPointDetail_001() {
		Logger.start(true,"获取我的积分-代理");
		try {
			addPointBean pointBean=GodmchManageCallService.addPoint();
			bean.setUserId(pointBean.getUserId());
			bean.setPageIndex(1);
			bean.setPageSize(5);
			call.setData(bean);
			call.callService();			
			
			SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss", Locale.CHINA);
			Logger.verifyEquals("200", call.getStatusCode1(), "验证statusCode");
			JSONArray return_jArray=call.getDetailList();
			point_change_detailWapper detailWapper=new point_change_detailWapper();
			
			point_change_detailExample example=new point_change_detailExample();
			example.createCriteria().andUser_idEqualTo(bean.getUserId());
			example.setOrderByClause(" create_Time desc ");
			 
			List<point_change_detail>  DB_details=detailWapper.selectByExample(example);
			Logger.verifyEquals(DB_details.size(), call.getTotal(), "验证Total");
			for(int i=0;i<DB_details.size();i++)
			{
				JSONObject jObject=new JSONObject(return_jArray.get(i).toString());
				point_change_detail DB_detail=DB_details.get(i);
				Logger.verifyEquals(DB_detail.getPoint_value(),jObject.getInt("point"), "验证Point_value");
				//Logger.verifyEquals(f.parse(new Date((DB_detail.getCreate_time()).toString()).toString()),jObject.getString("changeTime"), "验证changeTime");
				Logger.verifyEquals(DB_detail.getRemark(),jObject.getString("changeRemark"), "验证changeRemark");
			}
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}